﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Log
{
    //protected FileStream stream;
    protected int Day;
    public string Folder;
    public string FileName;
    public Log(string folder)
    {
        var now = DateTime.Now;
        string name = now.Year + "-" + now.Month + "-" + now.Day;
        Folder = "log/" + folder + "/" + name;
        if (!Directory.Exists(Folder))
            Directory.CreateDirectory(Folder);
        FileName = now.Hour + "-" + now.Minute + "-" + now.Second;
    }
    public void Delete()
    {
        string path = Folder + "/" + FileName;
        if (File.Exists(path))
            File.Delete(path);
    }
    public void Write(string msg)
    {
        var now = DateTime.Now;
        string path = Folder + "/" + FileName;
        string content = now.Hour + "-" + now.Minute + "-" + now.Second + "\n" + msg + "\n";
        try
        {
            File.AppendAllText(path, content);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.StackTrace);
        }
    }
}
